﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseFunction;
using BaseFunction.DEncrypt;

namespace YY.Web.MyAgent
{
    public partial class ModifyPwd : BaseFunction.LoginHelp
    {
        private Model.agent_users model;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                model = base.GetSessionModel();
                txtUserName.Text = model.user_name;
                txtRealName.Text = model.true_name;
                txtTelephone.Text = model.telphone;
                txtEmail.Text = model.e_mail;
            }
        }

        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            model = base.GetSessionModel();
            if (DESEncrypt.Encrypt(txtOldPassword.Text.Trim(), model.salt) != model.password)
            {
                MessageBox.Show(this.Page, "旧密码不正确！");
                return;
            }
            model.password = DESEncrypt.Encrypt(txtPassword.Text.Trim(), model.salt);
            model.true_name = txtRealName.Text.Trim();
            model.telphone = txtTelephone.Text.Trim();
            model.e_mail = txtEmail.Text.Trim();

            if (!BaseFunction.StaticTableClass.agent_users_Help.bll_agent_users.Update(model))
            {
                MessageBox.Show(this.Page, "保存过程中发生错误！");
                return;
            }

            MessageBox.ParentJscriptMsg(this.Page, "密码修改成功！", "ModifyPwd.aspx");
        }
    }
}